package com.ruoyi.gzs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gzs.domain.GzsPersonplan;
import com.ruoyi.gzs.service.IGzsPersonplanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 个人方案Controller
 * 
 * @author Liurenyi
 * @date 2022-06-29
 */
@RestController
@RequestMapping("/personplan/personplan")
public class GzsPersonplanController extends BaseController
{
    @Autowired
    private IGzsPersonplanService gzsPersonplanService;

    /**
     * 查询个人方案列表
     */
    @PreAuthorize("@ss.hasPermi('personplan:personplan:list')")
    @GetMapping("/list")
    public TableDataInfo list(GzsPersonplan gzsPersonplan)
    {
        startPage();
        List<GzsPersonplan> list = gzsPersonplanService.selectGzsPersonplanList(gzsPersonplan);
        return getDataTable(list);
    }

    /**
     * 导出个人方案列表
     */
    @PreAuthorize("@ss.hasPermi('personplan:personplan:export')")
    @Log(title = "个人方案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GzsPersonplan gzsPersonplan)
    {
        List<GzsPersonplan> list = gzsPersonplanService.selectGzsPersonplanList(gzsPersonplan);
        ExcelUtil<GzsPersonplan> util = new ExcelUtil<GzsPersonplan>(GzsPersonplan.class);
        util.exportExcel(response, list, "个人方案数据");
    }

    /**
     * 获取个人方案详细信息
     */
    @PreAuthorize("@ss.hasPermi('personplan:personplan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(gzsPersonplanService.selectGzsPersonplanById(id));
    }

    /**
     * 新增个人方案
     */
    @PreAuthorize("@ss.hasPermi('personplan:personplan:add')")
    @Log(title = "个人方案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GzsPersonplan gzsPersonplan)
    {
        return toAjax(gzsPersonplanService.insertGzsPersonplan(gzsPersonplan));
    }

    /**
     * 修改个人方案
     */
    @PreAuthorize("@ss.hasPermi('personplan:personplan:edit')")
    @Log(title = "个人方案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GzsPersonplan gzsPersonplan)
    {
        return toAjax(gzsPersonplanService.updateGzsPersonplan(gzsPersonplan));
    }

    /**
     * 删除个人方案
     */
    @PreAuthorize("@ss.hasPermi('personplan:personplan:remove')")
    @Log(title = "个人方案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gzsPersonplanService.deleteGzsPersonplanByIds(ids));
    }
}
